<!-- 线路接通率 -->
<template>
	<div id="LineQuality">
		<a-card :bordered="false">
			<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
				<a-row :gutter="24">
					<a-col :span="6">
						<a-form-item label="线路号码" name="caller">
							<!-- <a-select v-model:value="searchFormState.caller" placeholder="请选择线路" allowClear>
								<a-select-option v-for="item in callerNumberList" :key="item.ZCallerName" :value="item.ZCaller">
									<a-tooltip :title="item.ZCallerName" placement="right">
										{{ item.ZCallerName }}
									</a-tooltip>
								</a-select-option>
							</a-select> -->
							<a-input v-model:value="searchFormState.caller" placeholder="请输入线路号码" allowClear></a-input>
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-form-item label="时间范围" name="dateRange">
							<a-range-picker v-model:value="searchFormState.dateRange" valueFormat="YYYY-MM-DD" :allowClear="false" />
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
						<a-button style="margin: 0 8px" @click="reset">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</a-card>
		<a-card :bordered="false" class="mt-2">
			<s-table ref="tableRef" :columns="columns" :data="loadData" bordered :toolConfig="toolConfig"> </s-table>
		</a-card>
	</div>
</template>
<script setup name="LineQuality">
	import passQualityLineApi from '@/api/tjzy/passQuality/line/passQualityLineApi'
	import dayjs from 'dayjs'
	import htWebCall from '@/plugins/htWebCall'
	// ===========================================DATA======================================================
	const callerNumberList = htWebCall.callerNumberList
	const searchFormState = ref({
		caller: undefined,
		dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
	})
	const searchFormRef = ref()
	const tableRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: false, striped: false }
	const columns = [
		{
			title: '线路名称',
			dataIndex: 'callName'
		},
		{
			title: '时间范围',
			dataIndex: 'timeRange'
		},
		{
			title: '应答率',
			dataIndex: 'ringRate',
			customRender: ({ text }) => {
				return `${(text * 100).toFixed(2)}%`
			}
		},
		{
			title: '接通率',
			dataIndex: 'connectRate',
			customRender: ({ text }) => {
				return `${(text * 100).toFixed(2)}%`
			}
		}
	]
	// ===========================================WATCH=====================================================
	// ===========================================LIFECYCLE HOOKS===========================================
	// ===========================================METHODS==================================================
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
	//
	// ===========================================REQUEST==================================================
	const loadData = (parameter) => {
		const data = {
			caller: searchFormState.value.caller,
			beginTime: `${searchFormState.value.dateRange[0]} 00:00:00`,
			endTime: `${searchFormState.value.dateRange[1]} 23:59:59`,
			current: parameter.current,
			size: parameter.size
		}
		return passQualityLineApi.callerRate(data).then((res) => {
			if (res && res.records && res.records.length > 0) {
				res.records.forEach((item) => {
					item.timeRange = `${searchFormState.value.dateRange[0]} 至 ${searchFormState.value.dateRange[1]}`
				})
			}
			return res
		})
	}
</script>
<style lang="less" scoped></style>
